package fitnesshub.controller;
import fitnesshub.pojo.dto.BuyMemberDTO;
import fitnesshub.pojo.dto.MemberPageQueryDTO;
import fitnesshub.result.PageResult;
import fitnesshub.result.Result;

import fitnesshub.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理
 */
@RestController
@Slf4j
@RequestMapping("/admin/memberInfo")
public class AdminMemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 用户分页
     * @return
     */
    //alt+enter快捷创建对象
    @GetMapping("/page")
    public Result<PageResult> page(MemberPageQueryDTO memberPageQueryDTO) {
        log.info("用户分页查询，参数：{}", memberPageQueryDTO);
        PageResult pageResult = memberService.page(memberPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 购买会员
     * @param buyMemberDTO
     * @return
     */
    @PutMapping("/update/buyMember")
    public Result buyMember(@RequestBody BuyMemberDTO buyMemberDTO) {
        log.info("购买会员:{}", buyMemberDTO);
        memberService.buyMember(buyMemberDTO);
        return Result.success();
    }
}